package com.hlt.controller.admin;

import com.hlt.dto.CommentsPageQueryDTO;
import com.hlt.entity.Comments;
import com.hlt.result.PageResult;
import com.hlt.result.Result;
import com.hlt.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@Controller("adminCommentsController")
@RequestMapping("/comments")
@Slf4j
@Api(tags = "评论接口")
public class CommentsController {

    @Autowired
    private ICommentsService commentsService;
    /**
     * 新增评论
     */
    @PostMapping("/save")
    @ApiOperation("新增评论")
    public Result save(@RequestBody Comments comments) {
        log.info("新增评论：{}",comments);
        commentsService.save(comments);
        return Result.success();
    }

    /**
     * 删除评论
     */
    @DeleteMapping("/{commentId}")
    @ApiOperation("删除评论")
    public Result delete(@PathVariable Long commentId) {
        log.info("删除评论：{}",commentId);
        commentsService.removeById(commentId);
        return Result.success();
    }

    /**
     * 根据id查询评论
     */
    @GetMapping("/{commentId}")
    @ApiOperation("根据id查询评论")
    public Result getById(@PathVariable Long commentId) {
        log.info("根据id查询评论：{}",commentId);
        Comments comments = commentsService.getById(commentId);
        return Result.success(comments);
    }

    /**
     * 修改评论
     */
    @PutMapping("/update")
    @ApiOperation("修改评论")
    public Result update(@RequestBody Comments comments) {
        log.info("修改评论：{}",comments);
        commentsService.updateById(comments);
        return Result.success();
    }

    /**
     * 分页查询评论
     */
    @PostMapping("/page")
    @ApiOperation("分页查询评论")
    public Result page(@RequestBody CommentsPageQueryDTO commentsPageQueryDTO) {
        log.info("分页查询评论：{}",commentsPageQueryDTO);
        PageResult pageResult = commentsService.pageQuery(commentsPageQueryDTO);
        return Result.success(pageResult);
    }
}
